package org.example.processor;

import cn.hutool.core.date.DateTime;
import lombok.Getter;
import lombok.Setter;
import org.example.enums.EndpointEnum;
import org.example.plugin.HeartBeat;
import org.smartboot.socket.StateMachineEnum;
import org.smartboot.socket.extension.processor.AbstractMessageProcessor;
import org.smartboot.socket.transport.AioSession;

import java.util.concurrent.TimeUnit;

/**
 * @author Tamako
 * @since 2025-07-21 09:29
 */
public class MyProcessor extends AbstractMessageProcessor<String> {
    @Getter
    @Setter
    private EndpointEnum endpoint;

    public MyProcessor(EndpointEnum endpointEnum) {
        super();
        this.endpoint = endpointEnum;
    }

    @Override
    public void process0(AioSession session, String msg) {
        System.out.println(endpoint + "收到消息：" + msg);
    }

    @Override
    public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
        System.out.println(DateTime.now().toString("yyyy-MM-dd hh:mm:ss.SSS") + endpoint.toString() + "状态触发" + stateMachineEnum + (throwable != null ? ("\n" + throwable) : ""));
    }
}
